package com.hhkj.generator.entity;

import com.hhkj.generator.common.JavaMySQLTypeMapper;
import com.hhkj.generator.util.StringUtil;
import lombok.Data;

@Data
public class FieldItem {

	private String sqlCode;

	private String name;

	private String sqlType;

	private String isNotNull;

	private String defaultValue;

	private String note;

	private String javaCode;

	private String javaType;

	public FieldItem(String sqlCode, String name, String sqlType, String isNotNull, String defaultValue, String note) {
		this.sqlCode = sqlCode;
		this.name = name;
		this.sqlType = sqlType;
		this.isNotNull = isNotNull;
		this.defaultValue = defaultValue;
		this.note = note != null ? note : "";
		this.javaType = JavaMySQLTypeMapper.getInstance().getBySQLType(sqlType);
		this.javaCode = StringUtil.camelName(sqlCode);
	}

	public FieldItem() {
	}

	public static FieldItem toFieldItem(ExcelFieldItem excelFieldItem) {
		FieldItem fieldItem = new FieldItem(excelFieldItem.getCode(), excelFieldItem.getName(), excelFieldItem.getType(),
				excelFieldItem.getIsNotNull(), excelFieldItem.getDefaultValue(), excelFieldItem.getNote());
		return fieldItem;
	}

	public boolean isNull(){
		return isNotNull != null && !isNotNull.equals("是");
	}

	public boolean hasDefaultValue() {
		return defaultValue != null && !defaultValue.isEmpty();
	}


}
